// pages/student-info/student-info.js
import { get, post } from "../../api/request";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentStep: 0,
    steps: ['基本信息', '填报必要信息', '私人问题', '发展与理想'],
    gender: '',
    isArtStudent: '',
    isSportsStudent: '',
    isAgricultural: '',
    hasPreAdmission: '',
    considerPreAdmission: '',
    needFamilySupport: '',
    Political: false,
    Guardian: false,
    politicalStatus: '',
    guardianStatus: '',
    FatherPopup: false,
    fatherStatus: '',
    MotherPopup: false,
    motherStatus: '',
    JobPopup: false,
    jobStatus: '',
    YourJobPopup: false,
    DevelopmentPopup: false,
    yourJobStatus: '',
    developmentStatus: '',
    MainlandPopup: false,
    mainlandStatus: '',
    MajorPopup: false,
    majorStatus: '',
    StylePopup: false,
    styleStatus: '',
    jobOptions: [],
    mainlandOptions: [],
    majorOptions: [],
    parentJobOptions: [],
    developmentOptions: [],
    formData: {
      name: '',
      collegeScore: '',
      place: '',
      artScore: '',
      sportScore: '',
      contactPhone: '',
      parentPhone: '',
      targeted: '',
      almaMater: '',
      eiBudget: '',
      subject: '',
      guardian: '',
      father: '',
      fatherValue: '',
      mother: '',
      motherValue: '',
      job: '',
      jobValue: '',
      yourJob: '',
      development: '',
      developmentValue: '',
      mainland: '',
      mainlandValue: '',
      major: '',
      majorValue: '',
      style: ''
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  // 政审
  Political() {
    this.setData({
      Political: true
    });
  },

  // 监护人
  guardian() {
    this.setData({
      Guardian: true
    });
  },

  // 父亲
  Father() {
    this.setData({
      FatherPopup: true
    });
  },

  // 母亲
  Mother() {
    this.setData({
      MotherPopup: true
    });
  },

  // 工作意味着什么
  job() {
    this.setData({
      JobPopup: true
    });
  },

  // 您认为的工作意味着什么
  yourJob() {
    this.setData({
      YourJobPopup: true
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    // 先加载工作列表数据，成功后再获取用户信息
    this.requestItem().then(() => {
      // 在列表数据加载完成后再获取用户信息
      this.getMyInfo();
    }).catch(() => {
      // 即使列表数据加载失败，也尝试获取用户信息
      this.getMyInfo();
    });
  },

  /**
   * 数据请求
   */
  requestItem() {
    // 将所有请求合并为一个Promise，以便知道何时所有数据都已加载
    const promises = [];

    // 获取工作选项
    promises.push(
      get(`/index/enum_list?key=fm_job`).then(res => {
        if (res && res.code === 200 && res.data && res.data.length > 0) {
          this.setData({
            jobOptions: res.data
          });
        }
      }).catch(err => {
        console.error('获取工作选项失败', err);
      })
    );

    // 获取内地选项
    promises.push(
      get(`/index/enum_list?key=mp`).then(res => {
        if (res && res.code === 200 && res.data && res.data.length > 0) {
          this.setData({
            mainlandOptions: res.data
          });
        }
      }).catch(err => {
        console.error('获取内地选项失败', err);
      })
    );

    // 获取专业倾向
    promises.push(
      get(`/index/enum_list?key=profess`).then(res => {
        if (res && res.code === 200 && res.data && res.data.length > 0) {
          this.setData({
            majorOptions: res.data
          });
        }
      }).catch(err => {
        console.error('获取专业倾向选项失败', err);
      })
    );

    // 获取父母认为的工作意味着什么
    promises.push(
      get(`/index/enum_list?key=occ_type`).then(res => {
        if (res && res.code === 200 && res.data && res.data.length > 0) {
          this.setData({
            parentJobOptions: res.data
          });
        }
      }).catch(err => {
        console.error('获取父母认为的工作意味着什么选项失败', err);
      })
    );

    // 获取个人发展计划
    promises.push(
      get(`/index/enum_list?key=dp`).then(res => {
        if (res && res.code === 200 && res.data && res.data.length > 0) {
          this.setData({
            developmentOptions: res.data
          });
        }
      }).catch(err => {
        console.error('获取个人发展计划选项失败', err);
      })
    );

    // 返回一个Promise，当所有请求完成时解析
    return Promise.all(promises);
  },

  /**
   * 用户详情信息
   */
  getMyInfo() {
    get('/user/my_info').then(res => {
      console.log('用户详情信息', res);
      if (res && res.code === 200 && res.data) {
        const userData = res.data;
        // 处理性别
        this.setData({
          gender: userData.sex === 1 ? 'female' : userData.sex === 0 ? 'male' : '',
        });
        // 处理是否艺考
        this.setData({
          isArtStudent: userData.is_art_exam === 1 ? 'yes' : userData.is_art_exam === 0 ? 'no' : '',
        });
        // 处理是否体考
        this.setData({
          isSportsStudent: userData.is_sport === 1 ? 'yes' : userData.is_sport === 0 ? 'no' : '',
        });
        // 处理是否农业户口
        this.setData({
          isAgricultural: userData.rural_hukou === 1 ? 'yes' : userData.rural_hukou === 0 ? 'no' : '',
        });
        // 处理是否警校提前批次通过审核
        this.setData({
          hasPreAdmission: userData.pea_approval === 1 ? 'yes' : userData.pea_approval === 0 ? 'no' : '',
        });
        // 处理是否考虑提前批次
        this.setData({
          considerPreAdmission: userData.pea === 1 ? 'yes' : userData.pea === 0 ? 'no' : '',
        });
        // 处理家庭资源是否有帮助
        this.setData({
          needFamilySupport: userData.family_reso === 1 ? 'yes' : userData.family_reso === 0 ? 'no' : '',
        });

        // 设置表单数据
        let formData = {
          name: userData.real_name || '',
          collegeScore: userData.college_score !== null ? userData.college_score : '',
          place: userData.place !== null ? userData.place : '',
          artScore: userData.art_score !== null ? userData.art_score : '',
          contactPhone: userData.contact_number || '',
          parentPhone: userData.parent_phone || '',
          targeted: userData.targeted || '',
          almaMater: userData.alma_mater || '',
          eiBudget: userData.ei_budget || '',
          fatherValue: userData.f_job || '',
          motherValue: userData.m_job || '',
          jobValue: userData.pp_work || '',
          developmentValue: userData.idp || '',
          mainlandValue: userData.inland || '',
          majorValue: userData.tt_specialize || ''
        };

        // 处理政审状态
        let political = '';
        if (userData.political === -1) {
          political = '担心';
        } else if (userData.political === 0) {
          political = '无大碍';
        } else if (userData.political === 1) {
          political = '不担心';
        }

        // 处理监护人情况
        let guardian = '';
        if (userData.guardian === 1) {
          guardian = '父母';
        } else if (userData.guardian === 2) {
          guardian = '仅父亲';
        } else if (userData.guardian === 3) {
          guardian = '仅母亲';
        } else if (userData.guardian === 4) {
          guardian = '其他';
        }

        // 处理您认为的工作意味着什么
        let yourJob = '';
        if (userData.mow === 0) {
          yourJob = '简单';
        } else if (userData.mow === 1) {
          yourJob = '中等';
        } else if (userData.mow === 2) {
          yourJob = '困难';
        } else if (userData.mow === 3) {
          yourJob = '极难';
        }

        // 处理填报风格
        let style = '';
        if (userData.fill_style === 0) {
          style = '指定目标';
        } else if (userData.fill_style === 1) {
          style = '冒险风格';
        } else if (userData.fill_style === 2) {
          style = '保底风格';
        } else if (userData.fill_style === 3) {
          style = '靠你了';
        }

        // 更新状态显示
        this.setData({
          politicalStatus: political,
          guardianStatus: guardian,
          yourJobStatus: yourJob,
          styleStatus: style,
          'formData.subject': political,
          'formData.guardian': guardian,
          'formData.yourJob': yourJob,
          'formData.style': style,
          'formData': formData
        });

        // 根据job选项列表匹配父亲和母亲职业的label
        this.updateParentJobLabels();

        // 更新发展计划、想不想去内地、专业倾向的标签
        this.updateOtherLabels();
      }
    });
  },

  // 更新父母职业标签
  updateParentJobLabels() {
    if (this.data.jobOptions && this.data.jobOptions.length > 0) {
      // 找到父亲职业对应的标签
      if (this.data.formData.fatherValue) {
        const fatherJob = this.data.jobOptions.find(item =>
          item.value === parseInt(this.data.formData.fatherValue));
        if (fatherJob) {
          this.setData({
            fatherStatus: fatherJob.label,
            'formData.father': fatherJob.label
          });
        }
      }

      // 找到母亲职业对应的标签
      if (this.data.formData.motherValue) {
        const motherJob = this.data.jobOptions.find(item =>
          item.value === parseInt(this.data.formData.motherValue));
        if (motherJob) {
          this.setData({
            motherStatus: motherJob.label,
            'formData.mother': motherJob.label
          });
        }
      }

      // 找到工作意味着什么对应的标签
      if (this.data.formData.jobValue && this.data.parentJobOptions) {
        const parentJob = this.data.parentJobOptions.find(item =>
          item.value === parseInt(this.data.formData.jobValue));
        if (parentJob) {
          this.setData({
            jobStatus: parentJob.label,
            'formData.job': parentJob.label
          });
        }
      }
    }
  },

  // 更新其他标签
  updateOtherLabels() {
    // 更新发展计划标签
    if (this.data.formData.developmentValue && this.data.developmentOptions) {
      const development = this.data.developmentOptions.find(item =>
        item.value === parseInt(this.data.formData.developmentValue));
      if (development) {
        this.setData({
          developmentStatus: development.label,
          'formData.development': development.label
        });
      }
    }

    // 更新想不想去内地标签
    if (this.data.formData.mainlandValue && this.data.mainlandOptions) {
      const mainland = this.data.mainlandOptions.find(item =>
        item.value === parseInt(this.data.formData.mainlandValue));
      if (mainland) {
        this.setData({
          mainlandStatus: mainland.label,
          'formData.mainland': mainland.label
        });
      }
    }

    // 更新专业倾向标签
    if (this.data.formData.majorValue && this.data.majorOptions) {
      const major = this.data.majorOptions.find(item =>
        item.value === parseInt(this.data.formData.majorValue));
      if (major) {
        this.setData({
          majorStatus: major.label,
          'formData.major': major.label
        });
      }
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },

  // 切换性别
  selectGender(e) {
    const gender = e.currentTarget.dataset.gender;
    this.setData({
      gender
    });
  },

  // 选择是否
  selectYesNo(e) {
    const { field } = e.currentTarget.dataset;
    const value = e.currentTarget.dataset.value;
    this.setData({
      [field]: value
    });
  },

  // 下一步
  nextStep() {
    const { currentStep, steps } = this.data;
    if (currentStep < steps.length - 1) {
      this.setData({
        currentStep: currentStep + 1
      });
    } else {
      // 表单提交完成
      wx.showToast({
        title: '提交成功',
        icon: 'success'
      });
    }
  },

  // 返回并保存
  backAndSave() {
    // 收集所有表单数据
    const formDataToSubmit = {
      // 基本信息
      real_name: this.data.formData.name || '',
      sex: this.data.gender === 'male' ? 0 : 1,
      college_score: parseInt(this.data.formData.collegeScore || 0),
      place: parseInt(this.data.formData.place || 0),
      is_art_exam: this.data.isArtStudent === 'yes' ? 1 : 0,
      art_score: this.data.isArtStudent === 'yes' ? parseInt(this.data.formData.artScore || 0) : 0,
      is_sport: this.data.isSportsStudent === 'yes' ? 1 : 0,
      contact_number: this.data.formData.contactPhone || '',
      parent_phone: this.data.formData.parentPhone || '',

      // 填报必要信息
      rural_hukou: this.data.isAgricultural === 'yes' ? 1 : 0,
      pea_approval: this.data.hasPreAdmission === 'yes' ? 1 : 0,
      pea: this.data.considerPreAdmission === 'yes' ? 1 : 0,
      targeted: this.data.formData.targeted || '',
      alma_mater: this.data.formData.almaMater || '',

      // 私人问题
      political: this.getPoliticalValue(),
      guardian: this.getGuardianValue(),
      f_job: this.data.formData.fatherValue !== '' ? parseInt(this.data.formData.fatherValue) : 0,
      m_job: this.data.formData.motherValue !== '' ? parseInt(this.data.formData.motherValue) : 0,
      pp_work: this.data.formData.jobValue !== '' ? parseInt(this.data.formData.jobValue) : 0,
      ei_budget: this.data.formData.eiBudget || '',
      family_reso: this.data.needFamilySupport === 'yes' ? 1 : 0,

      // 发展与理想
      mow: this.getYourJobValue(),
      idp: this.data.formData.developmentValue !== '' ? parseInt(this.data.formData.developmentValue) : 0,
      inland: this.data.formData.mainlandValue !== '' ? parseInt(this.data.formData.mainlandValue) : 0,
      towards: '',  // 倾向城市，当前表单中未收集
      tt_specialize: this.data.formData.majorValue !== '' ? parseInt(this.data.formData.majorValue) : 0,
      fill_style: this.getStyleValue()
    };

    // 静默提交数据
    post('/user/up_info', formDataToSubmit).catch(err => {
      console.error('保存表单失败', err);
    });

    // 无论提交成功与否都执行返回操作
    const { currentStep } = this.data;
    if (currentStep > 0) {
      this.setData({
        currentStep: currentStep - 1
      });
    } else {
      wx.navigateBack();
    }
  },

  // 完成提交
  submitForm() {
    // 验证表单
    if (!this.validateForm()) {
      return;
    }
    // 收集所有表单数据
    const formDataToSubmit = {
      // 基本信息
      real_name: this.data.formData.name || '',
      sex: this.data.gender === 'male' ? 0 : 1,
      college_score: parseInt(this.data.formData.collegeScore || 0),
      place: parseInt(this.data.formData.place || 0),
      is_art_exam: this.data.isArtStudent === 'yes' ? 1 : 0,
      art_score: this.data.isArtStudent === 'yes' ? parseInt(this.data.formData.artScore || 0) : 0,
      is_sport: this.data.isSportsStudent === 'yes' ? 1 : 0,
      contact_number: this.data.formData.contactPhone || '',
      parent_phone: this.data.formData.parentPhone || '',
      // 填报必要信息
      rural_hukou: this.data.isAgricultural === 'yes' ? 1 : 0,
      pea_approval: this.data.hasPreAdmission === 'yes' ? 1 : 0,
      pea: this.data.considerPreAdmission === 'yes' ? 1 : 0,
      targeted: this.data.formData.targeted || '',
      alma_mater: this.data.formData.almaMater || '',
      // 私人问题
      political: this.getPoliticalValue(),
      guardian: this.getGuardianValue(),
      f_job: this.data.formData.fatherValue !== '' ? parseInt(this.data.formData.fatherValue) : 0,
      m_job: this.data.formData.motherValue !== '' ? parseInt(this.data.formData.motherValue) : 0,
      pp_work: this.data.formData.jobValue !== '' ? parseInt(this.data.formData.jobValue) : 0,
      ei_budget: this.data.formData.eiBudget || '',
      family_reso: this.data.needFamilySupport === 'yes' ? 1 : 0,
      // 发展与理想
      mow: this.getYourJobValue(),
      idp: this.data.formData.developmentValue !== '' ? parseInt(this.data.formData.developmentValue) : 0,
      inland: this.data.formData.mainlandValue !== '' ? parseInt(this.data.formData.mainlandValue) : 0,
      towards: '',  // 倾向城市，当前表单中未收集
      tt_specialize: this.data.formData.majorValue !== '' ? parseInt(this.data.formData.majorValue) : 0,
      fill_style: this.getStyleValue()
    };
    // 显示加载中提示
    wx.showLoading({
      title: '提交中',
    });
    // 发送请求提交数据
    post('/user/up_info', formDataToSubmit).then(res => {
      console.log('提交结果', res);
      wx.hideLoading();
      if (res && res.code === 200) {
        wx.showToast({
          title: res.message,
          icon: 'success',
          duration: 2000,
          success: () => {
            // 提交成功后返回
            setTimeout(() => {
              wx.navigateBack();
            }, 2000);
          }
        });
      } else {
        wx.showToast({
          title: res.message || '提交失败',
          icon: 'none',
          duration: 2000
        });
      }
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({
        title: '提交失败，请重试',
        icon: 'none',
        duration: 2000
      });
      console.error('提交表单失败', err);
    });
  },

  // 表单验证
  validateForm() {
    // 基本信息验证
    if (!this.data.formData.name) {
      wx.showToast({
        title: '请输入姓名',
        icon: 'none'
      });
      return false;
    }

    if (!this.data.gender) {
      wx.showToast({
        title: '请选择性别',
        icon: 'none'
      });
      return false;
    }

    if (!this.data.formData.collegeScore) {
      wx.showToast({
        title: '请输入高考成绩',
        icon: 'none'
      });
      return false;
    }

    if (!this.data.formData.place) {
      wx.showToast({
        title: '请输入位次',
        icon: 'none'
      });
      return false;
    }

    if (this.data.isArtStudent === '') {
      wx.showToast({
        title: '请选择是否艺考',
        icon: 'none'
      });
      return false;
    }

    if (this.data.isArtStudent === 'yes' && !this.data.formData.artScore) {
      wx.showToast({
        title: '请输入艺考成绩',
        icon: 'none'
      });
      return false;
    }

    if (this.data.isSportsStudent === '') {
      wx.showToast({
        title: '请选择是否体考',
        icon: 'none'
      });
      return false;
    }

    if (this.data.isSportsStudent === 'yes' && !this.data.formData.sportScore) {
      wx.showToast({
        title: '请输入体考成绩',
        icon: 'none'
      });
      return false;
    }

    if (!this.data.formData.contactPhone) {
      wx.showToast({
        title: '请输入本人联系电话',
        icon: 'none'
      });
      return false;
    }

    if (!this.data.formData.parentPhone) {
      wx.showToast({
        title: '请输入家长联系电话',
        icon: 'none'
      });
      return false;
    }

    // 填报必要信息验证
    if (this.data.isAgricultural === '') {
      wx.showToast({
        title: '请选择是否农业户口',
        icon: 'none'
      });
      return false;
    }

    if (this.data.hasPreAdmission === '') {
      wx.showToast({
        title: '请选择是否警校提前批次通过审核',
        icon: 'none'
      });
      return false;
    }

    if (this.data.considerPreAdmission === '') {
      wx.showToast({
        title: '请选择是否考虑提前批次',
        icon: 'none'
      });
      return false;
    }

    // 私人问题验证
    if (!this.data.formData.subject) {
      wx.showToast({
        title: '请选择政审状态',
        icon: 'none'
      });
      return false;
    }

    if (!this.data.formData.guardian) {
      wx.showToast({
        title: '请选择监护人情况',
        icon: 'none'
      });
      return false;
    }

    if (this.data.formData.fatherValue === '') {
      wx.showToast({
        title: '请选择父亲职业',
        icon: 'none'
      });
      return false;
    }

    if (this.data.formData.motherValue === '') {
      wx.showToast({
        title: '请选择母亲职业',
        icon: 'none'
      });
      return false;
    }

    if (this.data.formData.jobValue === '') {
      wx.showToast({
        title: '请选择父母认为的工作意味着什么',
        icon: 'none'
      });
      return false;
    }

    if (!this.data.formData.eiBudget) {
      wx.showToast({
        title: '请输入父母对学生经济独立之前的经济投入预算',
        icon: 'none'
      });
      return false;
    }

    if (this.data.needFamilySupport === '') {
      wx.showToast({
        title: '请选择家庭资源对你以后就业是否有帮助',
        icon: 'none'
      });
      return false;
    }

    // 发展与理想验证
    if (!this.data.formData.yourJob) {
      wx.showToast({
        title: '请选择您认为的工作意味着什么',
        icon: 'none'
      });
      return false;
    }

    if (this.data.formData.developmentValue === '') {
      wx.showToast({
        title: '请选择个人发展计划',
        icon: 'none'
      });
      return false;
    }

    if (this.data.formData.mainlandValue === '') {
      wx.showToast({
        title: '请选择想不想去内地',
        icon: 'none'
      });
      return false;
    }

    if (this.data.formData.majorValue === '') {
      wx.showToast({
        title: '请选择专业倾向',
        icon: 'none'
      });
      return false;
    }

    if (!this.data.formData.style) {
      wx.showToast({
        title: '请选择填报风格',
        icon: 'none'
      });
      return false;
    }

    return true;
  },

  // 获取政审值
  getPoliticalValue() {
    switch (this.data.formData.subject) {
      case '担心':
        return -1;
      case '无大碍':
        return 0;
      case '不担心':
        return 1;
      default:
        return null;
    }
  },

  // 获取监护人情况值
  getGuardianValue() {
    switch (this.data.formData.guardian) {
      case '父母':
        return 1;
      case '仅父亲':
        return 2;
      case '仅母亲':
        return 3;
      case '其他':
        return 4;
      default:
        return null;
    }
  },

  // 获取您认为的工作意味着什么值
  getYourJobValue() {
    switch (this.data.formData.yourJob) {
      case '简单':
        return 0;
      case '中等':
        return 1;
      case '困难':
        return 2;
      case '极难':
        return 3;
      default:
        return null;
    }
  },

  // 获取填报风格值
  getStyleValue() {
    switch (this.data.formData.style) {
      case '指定目标':
        return 0;
      case '冒险风格':
        return 1;
      case '保底风格':
        return 2;
      case '靠你了':
        return 3;
      default:
        return null;
    }
  },

  // 关闭弹窗
  onSubjectClose() {
    this.setData({
      Political: false
    });
  },

  // 选择政审选项
  handleSubjectSelect(e) {
    const subject = e.currentTarget.dataset.subject;
    this.setData({
      politicalStatus: subject,
      'formData.subject': subject,
      Political: false  // 选择后自动关闭弹窗
    });
  },

  // 关闭监护人情况弹窗
  onGuardianClose() {
    this.setData({
      Guardian: false
    });
  },

  // 选择监护人情况选项
  handleGuardianSelect(e) {
    const guardian = e.currentTarget.dataset.guardian;
    this.setData({
      guardianStatus: guardian,
      'formData.guardian': guardian,
      Guardian: false  // 选择后自动关闭弹窗
    });
  },

  // 关闭父亲职业弹窗
  onFatherClose() {
    this.setData({
      FatherPopup: false
    });
  },

  // 选择父亲职业选项
  handleFatherSelect(e) {
    const { fatherJob } = e.currentTarget.dataset;
    const selectedJob = this.data.jobOptions.find(item => item.value.toString() === fatherJob.toString());
    if (selectedJob) {
      this.setData({
        fatherStatus: selectedJob.label,
        'formData.father': selectedJob.label,
        'formData.fatherValue': selectedJob.value,
        FatherPopup: false  // 选择后自动关闭弹窗
      });
    }
  },

  // 关闭母亲职业弹窗
  onMotherClose() {
    this.setData({
      MotherPopup: false
    });
  },

  // 选择母亲职业选项
  handleMotherSelect(e) {
    const { motherJob } = e.currentTarget.dataset;
    const selectedJob = this.data.jobOptions.find(item => item.value.toString() === motherJob.toString());
    if (selectedJob) {
      this.setData({
        motherStatus: selectedJob.label,
        'formData.mother': selectedJob.label,
        'formData.motherValue': selectedJob.value,
        MotherPopup: false  // 选择后自动关闭弹窗
      });
    }
  },

  // 关闭工作意味着什么弹窗
  onJobClose() {
    this.setData({
      JobPopup: false
    });
  },

  // 选择工作意味着什么选项
  handleJobSelect(e) {
    const { jobValue } = e.currentTarget.dataset;
    const selectedJob = this.data.parentJobOptions.find(item => item.value.toString() === jobValue.toString());
    if (selectedJob) {
      this.setData({
        jobStatus: selectedJob.label,
        'formData.job': selectedJob.label,
        'formData.jobValue': selectedJob.value,
        JobPopup: false  // 选择后自动关闭弹窗
      });
    }
  },

  // 关闭您认为的工作意味着什么弹窗
  onYourJobClose() {
    this.setData({
      YourJobPopup: false
    });
  },

  // 选择您认为的工作意味着什么选项
  handleYourJobSelect(e) {
    const yourJob = e.currentTarget.dataset.yourjob;
    this.setData({
      yourJobStatus: yourJob,
      'formData.yourJob': yourJob,
      YourJobPopup: false  // 选择后自动关闭弹窗
    });
  },

  // 添加个人发展计划弹窗方法
  development() {
    this.setData({
      DevelopmentPopup: true
    });
  },

  // 关闭个人发展计划弹窗
  onDevelopmentClose() {
    this.setData({
      DevelopmentPopup: false
    });
  },

  // 选择个人发展计划选项
  handleDevelopmentSelect(e) {
    const { developmentValue } = e.currentTarget.dataset;
    const selectedDevelopment = this.data.developmentOptions.find(item => item.value.toString() === developmentValue.toString());
    if (selectedDevelopment) {
      this.setData({
        developmentStatus: selectedDevelopment.label,
        'formData.development': selectedDevelopment.label,
        'formData.developmentValue': selectedDevelopment.value,
        DevelopmentPopup: false  // 选择后自动关闭弹窗
      });
    }
  },

  // 添加想不想去内地弹窗方法
  mainland() {
    this.setData({
      MainlandPopup: true
    });
  },

  // 关闭想不想去内地弹窗
  onMainlandClose() {
    this.setData({
      MainlandPopup: false
    });
  },

  // 选择想不想去内地选项
  handleMainlandSelect(e) {
    const { mainlandJob } = e.currentTarget.dataset;
    const selectedMainland = this.data.mainlandOptions.find(item => item.value.toString() === mainlandJob.toString());
    if (selectedMainland) {
      this.setData({
        mainlandStatus: selectedMainland.label,
        'formData.mainland': selectedMainland.label,
        'formData.mainlandValue': selectedMainland.value,
        MainlandPopup: false  // 选择后自动关闭弹窗
      });
    }
  },

  // 添加专业倾向弹窗方法
  major() {
    this.setData({
      MajorPopup: true
    });
  },

  // 关闭专业倾向弹窗
  onMajorClose() {
    this.setData({
      MajorPopup: false
    });
  },

  // 选择专业倾向选项
  handleMajorSelect(e) {
    const { majorJob } = e.currentTarget.dataset;
    const selectedMajor = this.data.majorOptions.find(item => item.value.toString() === majorJob.toString());
    if (selectedMajor) {
      this.setData({
        majorStatus: selectedMajor.label,
        'formData.major': selectedMajor.label,
        'formData.majorValue': selectedMajor.value,
        MajorPopup: false  // 选择后自动关闭弹窗
      });
    }
  },

  // 添加填报风格弹窗方法
  style() {
    this.setData({
      StylePopup: true
    });
  },

  // 关闭填报风格弹窗
  onStyleClose() {
    this.setData({
      StylePopup: false
    });
  },

  // 选择填报风格选项
  handleStyleSelect(e) {
    const style = e.currentTarget.dataset.style;
    this.setData({
      styleStatus: style,
      'formData.style': style,
      StylePopup: false  // 选择后自动关闭弹窗
    });
  },

  // 监听姓名输入
  handleNameInput(e) {
    this.setData({
      'formData.name': e.detail.value
    });
  },

  // 监听高考成绩输入
  handleCollegeScoreInput(e) {
    this.setData({
      'formData.collegeScore': e.detail.value
    });
  },

  // 监听位次输入
  handlePlaceInput(e) {
    this.setData({
      'formData.place': e.detail.value
    });
  },

  // 监听艺考成绩输入
  handleArtScoreInput(e) {
    this.setData({
      'formData.artScore': e.detail.value
    });
  },

  // 监听体考成绩输入
  handleSportScoreInput(e) {
    this.setData({
      'formData.sportScore': e.detail.value
    });
  },

  // 监听本人电话输入
  handleContactPhoneInput(e) {
    this.setData({
      'formData.contactPhone': e.detail.value
    });
  },

  // 监听家长电话输入
  handleParentPhoneInput(e) {
    this.setData({
      'formData.parentPhone': e.detail.value
    });
  },

  // 监听定向学校或专业输入
  handleTargetedInput(e) {
    this.setData({
      'formData.targeted': e.detail.value
    });
  },

  // 监听毕业学校和班级输入
  handleAlmaMaterInput(e) {
    this.setData({
      'formData.almaMater': e.detail.value
    });
  },

  // 监听经济预算输入
  handleEiBudgetInput(e) {
    this.setData({
      'formData.eiBudget': e.detail.value
    });
  },
})